//
//  HLTabBarController.m
//  HL-百思不得姐
//
//  Created by admin on 16/4/26.
//  Copyright © 2016年 CHL. All rights reserved.
//

#import "HLTabBarController.h"
#import "HLEssenceViewController.h"
#import "HLFriendTrendViewController.h"
#import "HLMeViewController.h"
#import "HLNewViewController.h"
#import "HLPublishViewController.h"
#import "UIImage+HLImage.h"
#import "HLTabBar.h"
#import "HLNavViewController.h"

@interface HLTabBarController ()

@end

@implementation HLTabBarController

//只调用一次
+ (void)load
{
    //获取全局的tabBarItem统一设置属性
    UITabBarItem *item = [UITabBarItem appearanceWhenContainedInInstancesOfClasses:@[self]];
    
    //setTitleTextAttributes富文本:描述一个文字颜色,字体,阴影,空心,图文混排
    //设置文字颜色
    NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
    attrs[NSForegroundColorAttributeName] = [UIColor blackColor];
    [item setTitleTextAttributes:attrs forState:UIControlStateSelected];
    
    //设置文字大小
    NSMutableDictionary *attrsNor = [NSMutableDictionary dictionary];
    attrsNor[NSFontAttributeName] = [UIFont systemFontOfSize:14];
    [item setTitleTextAttributes:attrsNor forState:UIControlStateNormal];
}

- (void)viewDidLoad {
    [super viewDidLoad];
   
    //添加所有子控制器
    [self setupAllChildVC];
    
    //设置tabBar上的按钮内容
    [self setupAllTabBarButton];
    
    //自定义tabBar
    [self setupTabBar];
}

#pragma mark - 自定义tabBar
- (void)setupTabBar
{
    UITabBar *tabBar = [[HLTabBar alloc] init];
    
    //tabBar 是只读属性，只能通过kvc或者runtime修改属性值
    [self setValue:tabBar forKey:@"tabBar"];
    
}

#pragma mark - 添加所有子控制器
- (void)setupAllChildVC
{
    
    // 精华
    UIViewController *essenceVC = [[HLEssenceViewController alloc] init];
    HLNavViewController *essenceNav = [[HLNavViewController alloc] initWithRootViewController:essenceVC];
    [self addChildViewController:essenceNav];
    
    // 新帖
    UIViewController *newVC = [[HLNewViewController alloc] init];
    HLNavViewController *newNav = [[HLNavViewController alloc] initWithRootViewController:newVC];
    [self addChildViewController:newNav];
    
    // 发布
//    UIViewController *publishVC = [[HLPublishViewController alloc] init];
//    [self addChildViewController:publishVC];
    
    // 关注
    UIViewController *friendTrendVC = [[HLFriendTrendViewController alloc] init];
    HLNavViewController *friendTrendNav = [[HLNavViewController alloc]initWithRootViewController:friendTrendVC];
    [self addChildViewController:friendTrendNav];
    
    // 我
    UITableViewController *meVC = [[HLMeViewController alloc] init];
    HLNavViewController *meNav = [[HLNavViewController alloc] initWithRootViewController:meVC];
    [self addChildViewController:meNav];
}

#pragma mark - 设置tabBar上的按钮内容
- (void)setupAllTabBarButton
{
    
    // 精华
    UINavigationController *essenceNav = self.childViewControllers[0];
    essenceNav.tabBarItem.title = @"精华";
    essenceNav.tabBarItem.image = [UIImage imageNamed:@"tabBar_essence_icon"];
    essenceNav.tabBarItem.selectedImage = [UIImage imageOriginalWithName:@"tabBar_essence_click_icon"];
    
    // 新帖
    UINavigationController *newNav = self.childViewControllers[1];
    newNav.tabBarItem.title = @"新帖";
    newNav.tabBarItem.image = [UIImage imageNamed:@"tabBar_new_icon"];
    newNav.tabBarItem.selectedImage = [UIImage imageOriginalWithName:@"tabBar_new_click_icon"];
    
    // 发布
//    UIViewController *publishVC = self.childViewControllers[2];
//    publishVC.tabBarItem.image = [UIImage imageNamed:@"tabBar_publish_icon"];
//    publishVC.tabBarItem.selectedImage = [UIImage imageOriginalWithName:@"tabBar_publish_click_icon"];
    
    // 关注
    UINavigationController *friendTrendNav = self.childViewControllers[2];
    friendTrendNav.tabBarItem.title = @"关注";
    friendTrendNav.tabBarItem.image = [UIImage imageNamed:@"tabBar_friendTrends_icon"];
    friendTrendNav.tabBarItem.selectedImage = [UIImage imageOriginalWithName:@"tabBar_friendTrends_click_icon"];
    
    // 我
    UINavigationController *meNav = self.childViewControllers[3];
    meNav.tabBarItem.title = @"我";
    meNav.tabBarItem.image = [UIImage imageNamed:@"tabBar_me_icon"];
    meNav.tabBarItem.selectedImage = [UIImage imageOriginalWithName:@"tabBar_me_click_icon"];
}

@end
